import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Solution solution = new Solution();

        int n1 = scanner.nextInt();
        int n2 = scanner.nextInt();

        System.out.println(solution.makeTheIntegerZero(n1,n2));
    }
}

class Solution {
    public int makeTheIntegerZero(int num1, int num2) {
        int k = 1;
        while (true){
            long x = num1 - (long)num2 * k;
            if(x<k){
                return -1;
            }

            //bitCount(long i)
            //返回指定的long值的二进制补码二进制表示中的 long数。
            if(k>=Long.bitCount(x)){
                return k;
            }
            k++;
        }
    }
}